package cn.hill4j.tool.spring.std.dispatch.controller;

import cn.hill4j.tool.spring.ext.dispatcher.DestinationFactory;
import cn.hill4j.tool.spring.ext.dispatcher.DispatchRoute;
import cn.hill4j.tool.spring.ext.dispatcher.exception.DispatchInvokerException;
import cn.hill4j.tool.spring.std.dispatch.service.DispatchData;
import cn.hill4j.tool.spring.std.dispatch.service.MyDispatcher;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/dispatch")
public class DispatchController {
    @Resource
    private MyDispatcher myDispatcher;
    @GetMapping("/test/{biz}/{str}")
    public String disPatchTest(@PathVariable("biz") String biz,@PathVariable("str") String str) throws DispatchInvokerException {
        return (String) DestinationFactory.selectHandler(new DispatchRoute("test",biz)).invoke(new Object[]{str});
    }

    @PostMapping()
    public String disPatch(@RequestBody DispatchData dispatchData) throws DispatchInvokerException {
        return (String)myDispatcher.dispatch(dispatchData);
    }
}
